- main_toolbar do |t|
  = t.edit resource
  -# t.destroy
  -#= t.new(params: {controller: :issues, target_id: resource.id, target_type: resource.class.name}, tool: 'new-issue')
  -#= t.new(params: {controller: :inspections, product_id: resource.id}, tool: 'eyedropper')

= main_informations attachment: true do
  = render 'picture'
  = infos do
    = product_info(:work_number, important: true)
    = product_info(:net_surface_area, important: true) do |population|
      = resource.net_surface_area.round(3).l
    = product_info(:variety, important: true, nomenclature: true)
    = product_info(:born_at, important: true)
    - if resource.dead_at
      = product_info(:dead_at, important: true)
    - if resource.born_at && resource.age >= 1.day
      = product_info(:age) do |age|
        %i.picto{class: "picto-clock-o"}
        = human_age(resource.born_at, display: 2)
    -# stock = resource.inspections.reorder(:sampled_at).last.product_stock_in_ground
    -# if resource.inspections.any? && stock
      .med-info
        %span.title= Product.human_attribute_name(:product_stock_in_ground)
        %span.value
          %i.picto{class: "picto-grain"}
          = stock.round(3).l
      - if resource.population && resource.population.to_d != 0.0
        .med-info
          %span.title= Product.human_attribute_name(:provisionnal_yield)
          %span.value
            %i.picto{class: "picto-grain"}
            - unit = stock.unit + "_per_" + resource.net_surface_area.unit
            = (stock.to_d / resource.population).in(unit).round(3).l
    = product_info(:status, important: true) do |status|
      = lights(status)
    .med-info
      %span.title= :ready_to_harvest.tl
      %span.value
        %i.picto{class: "picto-#{resource.ready_to_harvest? ? :done : :clear}"}
    = product_info :description
    = product_info :container do |container|
      %i.picto{class: "zone"}
      = link_to(container.work_name, {controller: container.type.tableize, action: :show, id: container.id})
    - if resource.customized?
      = attributes_list(stamps: false)
  = labels_info(resource.labels)
= cobbles do |c|

  - if resource.intervention_product_parameters.any?
    - c.cobble(:intervention_product_parameters, title: :x_interventions.tl(count: resource.interventions.count)) do
      = cobble_list(:intervention_product_parameters)

  - c.cobble(:trackings, title: :x_trackings.tl(count: resource.trackings.count)) do
    = cobble_toolbar do |t|
      = t.new(params: {controller: :trackings, product_id: resource.id, active: true})
    = cobble_list(:trackings)

  - c.cobble(:issues, title: :x_issues.tl(count: resource.issues.count)) do
    = cobble_toolbar do |t|
      = t.new(params: {controller: :issues, target_id: resource.id, target_type: resource.class.name})
    = cobble_list(:issues)

  - if resource.inspections.any?
    - render 'inspection_cobbles', c: c, resource: resource

  - c.cobble :plant_countings, title: :x_countings.tl(count: resource.plant_countings.count) do
    - if resource.activity.present?
      = cobble_toolbar do |t|
        = t.menu :new, icon: false do |menu|
          - resource.activity.plant_density_abaci.each do |abacus|
            - menu.item abacus.name, { action: :new, controller: :plant_countings, plant_id: resource.id, plant_density_abacus_id: abacus.id }, title: abacus.name
    = cobble_list :plant_countings

  - c.cobble(:inspections, title: :x_inspections.tl(count: resource.inspections.count)) do
    -# FIXME Add activity in URL to get link working
    -# = cobble_toolbar do |t|
      = t.new(params: { controller: :inspections, product_id: resource.id })
    = cobble_list(:inspections)

  =# render partial: 'backend/shared/distributions', locals: {c: c}
